home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / KoStoreDevice.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  2.6 KB  |  89 lines

  1. /* This file is part of the KDE project
  2.    Copyright (C) 2000 David Faure <faure@kde.org>
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License as published by the Free Software Foundation; either
  7.    version 2 of the License, or (at your option) any later version.
  8.  
  9.    This library is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.    Library General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU Library General Public License
  15.    along with this library; see the file COPYING.LIB.  If not, write to
  16.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.  * Boston, MA 02110-1301, USA.
  18. */
  19.  
  20. #ifndef koStoreDevice_h
  21. #define koStoreDevice_h
  22.  
  23. #include <KoStore.h>
  24.  
  25. /**
  26.  * This class implements a QIODevice around KoStore, so that
  27.  * it can be used to create a QDomDocument from it, to be written or read
  28.  * using QDataStream or to be written using QTextStream
  29.  */
  30. class KoStoreDevice : public QIODevice
  31. {
  32. public:
  33.   /// Note: KoStore::open() should be called before calling this.
  34.   KoStoreDevice( KoStore * store ) : m_store(store) {
  35.       setType( IO_Direct );
  36.   }
  37.   ~KoStoreDevice() {}
  38.  
  39.   bool open( int m ) {
  40.     if ( m & IO_ReadOnly )
  41.       return ( m_store->mode() == KoStore::Read );
  42.     if ( m & IO_WriteOnly )
  43.       return ( m_store->mode() == KoStore::Write );
  44.     return false;
  45.   }
  46.   void close() { }
  47.   void flush() { }
  48.  
  49.   Offset size() const {
  50.     if ( m_store->mode() == KoStore::Read )
  51.       return m_store->size();
  52.     else
  53.       return 0xffffffff;
  54.   }
  55.  
  56.   virtual Q_LONG readBlock( char *data, Q_ULONG maxlen ) { return m_store->read(data, maxlen); }
  57.   virtual Q_LONG writeBlock( const char *data, Q_ULONG len ) { return m_store->write( data, len ); }
  58.   // Not virtual, only to uncover shadow
  59.   Q_LONG writeBlock( const QByteArray& data ) { return QIODevice::writeBlock( data ); }
  60.  
  61.   int getch() {
  62.     char c[2];
  63.     if ( m_store->read(c, 1) == -1)
  64.       return -1;
  65.     else
  66.       return c[0];
  67.   }
  68.   int putch( int _c ) {
  69.     char c[2];
  70.     c[0] = _c;
  71.     c[1] = 0;
  72.     if (m_store->write( c, 1 ) == 1)
  73.       return _c;
  74.     else
  75.       return -1;
  76.   }
  77.   int ungetch( int ) { return -1; } // unsupported
  78.  
  79.   // See QIODevice
  80.   virtual bool at( Offset pos ) { return m_store->at(pos); }
  81.   virtual Offset at() const { return m_store->at(); }
  82.   virtual bool atEnd() const { return m_store->atEnd(); }
  83.  
  84. protected:
  85.   KoStore * m_store;
  86. };
  87.  
  88. #endif
  89.